home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3160 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: zeus.rbi.informatik.uni-frankfurt.de!gna1pc
  2. From: Ferber@zoology.uni-frankfurt.de (Michael Ferber)
  3. Newsgroups: comp.lang.c
  4. Subject: performance of fread
  5. Date: Mon, 22 Jan 96 08:36:57 GMT
  6. Organization: Uni Frankfurt
  7. Message-ID: <4eaecp$m5a@zeus.rbi.informatik.uni-frankfurt.de>
  8. NNTP-Posting-Host: gna1pc.zoologys.uni-frankfurt.de
  9. X-Newsreader: News Xpress Version 1.0 Beta #4
  10.  
  11. I have a file containing data (integers) which are arranged in the following 
  12. way:
  13. a1, b1, c1, d1, a2, b2, c2, d2, a3, b3 ........, dn
  14.  
  15. For further processing I have to put these data into arrays like:
  16.  
  17. a1, a2, .... an
  18. b1, b2, .... bn
  19.  
  20. or a twodimensional array like:
  21.  
  22. X[4][n]
  23.  
  24. I think there are several ways to do this.
  25. 1. To read each integer and put it into the appropriate array, and the read   
  26.    the next value. This assumes that I have call fread d * n times. Due to the 
  27.    fact that I have to read many (several thousand) integers this seems to be 
  28.    slow but easy to implement.
  29. 2. To read many integers into a buffer. And then copy the integers to their   
  30.    appropriate arrays. This seems to be faster, but more difficult to control 
  31.    compared with 3 and 1, because I always have to check if a new read is     
  32.  necessary while processing the data within the array.
  33. 3. To use the approach described in 1. but with a large buffer set with       
  34.    setvbuf.
  35. Furthermore I cannot read all the data of the file in a single turn because a 
  36. single file may contain a theoretically unlimited number of integers, usually 
  37. my files contain about 12 - 15 million points.
  38.  
  39. My question: How time consuming is the overhead of calling fread reading from 
  40. a large buffer compared to a for( ) loop which takes his data from a memory 
  41. block which was filled by a single call of fread. 
  42.  
  43. Any suggestions?
  44.  
  45. Thanks in advance
  46. Michael
  47.  
  48. ------------------------------------------------------------------------------------
  49. || Dr. Michael Ferber                     ||
  50. || Universitaet Frankfurt                 ||"science moves,
  51. || Zoologisches Institut                  || but slowly, slowly ......"
  52. || email: Ferber@zoology.uni-frankfurt.de ||                      Tennyson
  53. ------------------------------------------------------------------------------------
  54.